package com.topnav.mc.admin.entity.wrapper;

import com.js.lib.mybitsplus.JsWrapper;
import com.topnav.mc.admin.entity.param.DeviceAlarmParam;
import com.topnav.mc.base.comm.McJsWrapper;
import com.topnav.mc.base.mc.McWrapper;
import org.springframework.util.StringUtils;

/**
 * @Author: kenny
 * @Date: 2023/11/6 14:24
 */
public class DeviceAlarmWrapper extends McWrapper<DeviceAlarmParam> {
    public DeviceAlarmWrapper(DeviceAlarmParam entity) {
        super(entity);
        if (this.permissionGrade != null ){
            if (this.permissionGrade.getPermissionLevel() == 1){
                this.eq("d.user_id",this.permissionGrade.getUserId());
            }else if (this.permissionGrade.getPermissionLevel() == 2){
                this.eq("d.org_id",this.permissionGrade.getOrgId());
            }else if (this.permissionGrade.getPermissionLevel() == 3 || this.permissionGrade.getPermissionLevel() == 4){
                this.likeRight("o.path",this.permissionGrade.getOrgPath());
            }
        }
        if (entity != null){
            if (entity.getId()!=null){this.eq("a.id",entity.getId());}
            if (entity.getDeviceId()!=null){this.eq("a.id",entity.getDeviceId());}
            if (entity.getFromTime() != null) {this.ge("a.alarm_time", entity.getFromTime());}
            if (entity.getToTime() != null) {this.le("a.alarm_time", entity.getToTime());}
            if (entity.getAlarmCate() != null) {this.eq("a.alarm_cate", entity.getAlarmCate());}
            if (entity.getAlarmType() != null) {this.eq("a.alarm_type", entity.getAlarmType());}
            if (entity.getAlarmEvent() != null) {this.eq("a.alarm_event", entity.getAlarmEvent());}
            if (entity.getAlarmMode() != null) {this.eq("a.alarm_mode", entity.getAlarmMode());}

            if (entity.getOrgId() != null) {this.eq("d.org_id", entity.getOrgId());}
            if (entity.getUserId() != null) {this.eq("d.user_id", entity.getUserId());}
            if (entity.getDeviceId() != null) {this.eq("a.device_id", entity.getDeviceId());}
            if (entity.getDispose() != null) {this.eq("a.dispose", entity.getDispose());}

            if (!StringUtils.isEmpty(entity.getDisposeRemark())) {this.like("a.dispose_remark", entity.getDisposeRemark());}


            if (!StringUtils.isEmpty(entity.getDeviceCode())) {this.like("d.code", entity.getDeviceCode());}

            if (entity.getIsGroupBy()==null || entity.getIsGroupBy()==false){
                this.orderByDesc("a.id");
            }

        }
    }

}
